package com.endoc.news.fragment.homefragment;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentPagerAdapter;
import com.endoc.news.fragment.newslist.NewsFragment;
import com.endoc.news.netWoke.bean.NewsChannelsBean;
import java.util.List;

public class HomeFragmentAdapter extends FragmentPagerAdapter {
    List<NewsChannelsBean.ChannelList> mChannelList;

    public HomeFragmentAdapter(@NonNull FragmentManager fm) {
        super(fm);
    }

    @NonNull
    @Override
    public Fragment getItem(int position) {
        return NewsFragment.newInstance(mChannelList.get(position).channelId,mChannelList.get(position).name);
    }

    @Override
    public int getCount() {
        if (mChannelList != null) {
            return mChannelList.size();
        } else {
            return 0;
        }
    }

    public void setData(List<NewsChannelsBean.ChannelList> channelList){
        mChannelList =channelList;
        notifyDataSetChanged();
    }

    @Nullable
    @Override
    public CharSequence getPageTitle(int position) {
       // Logger.d("positon==="+position);
        return mChannelList.get(position).name;
    }
}
